package com.china.school.proxyfactory;

import com.china.school.interceptor.AroundTest;
import com.china.school.interceptor.BeforeTest;
import com.china.school.pojo.User;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.ProxyFactoryBean;

public class ProxyFactoryBeanTest {
    public static void main(String[] args) {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
//        proxyFactoryBean.set

        ProxyFactory factory = new ProxyFactory(new User());
        factory.addAdvice(new BeforeTest()); //单独的添加增强处理,那么对所有的pointcout都进行增强
        factory.addAdvice(new AroundTest());
        factory.addAdvice(new MethodInterceptor() {
            @Override
            public Object invoke(MethodInvocation invocation) throws Throwable {
                System.out.println("before...");
                Object result = invocation.proceed();
                System.out.println("after...");
                return result;
            }
        });

         User user = (User) factory.getProxy();

        user.eat();



    }



}
